<template>
  <div>
    <h3>权益添加</h3>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="right">权益名称</td>
          <td><input type="text" v-model="ojbinfo.Name" /></td>
        </tr>
        <tr>
          <td align="right">状态</td>
          <td>
            <input
              type="radio"
              name="ss"
              v-model="ojbinfo.State"
              :value="1"
            />开启
            <input
              type="radio"
              name="ss"
              v-model="ojbinfo.State"
              :value="2"
            />禁用
          </td>
        </tr>
        <tr>
          <td align="right"></td>
          <td><input type="button" value="添加" @click="Add" /></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { ref, reactive, onMounted, Static } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();

//声明向后端
let ojbinfo = reactive({
  Name: "", //姓名
  State: 1, //状态
});

//添加
const Add = () => {
  //1.非空+有效性
  if (ojbinfo.Name == "") {
    alert("不可为空");
    return;
  }
  //2.网络请求
  axios({
    url: "/api/Member/RightAdd",
    method: "post",
    data: ojbinfo,
  })
    .then((res) => {
      console.log(res);
      //唯一
      if (res.data == -1) {
        alert("权益不可重复");
        return;
      }
      alert("添加成功");
      //跳转
      router.push("/qyiList")
    })
    .catch((arr) => {
      alert("添加失败");
    });
};
</script>

<style scoped></style>
